<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <base href="/">
    <title>添加饭卡</title>
    <script type="text/javascript" src="h-ui/lib/html5shiv.js"></script>
    <script type="text/javascript" src="h-ui/lib/respond.min.js"></script>
    <link rel="stylesheet" type="text/css" href="h-ui/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="h-ui/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="h-ui/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="h-ui/static/h-ui.admin/skin/red/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="h-ui/static/h-ui.admin/css/style.css"/>
</head>
<body>
<div class="page-container">
    <form   class="form form-horizontal" id="addFrom" target="_parent">
        <div class="row cl">
            <div class="col-xs-6 col-sm-4 text-r">
                <span class="c-red">*</span>卡号：
            </div>
            <div class="col-sm-6">
                <input type="text" class="input-text radius" id="cardNum" name="cardNum"
                       placeholder="请输入卡号">
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-6 col-sm-4 text-r">
                <span class="c-red">*</span>
                金额：
            </div>
            <div class="col-sm-6">
                <input type="text" class="input-text radius" id="balance" name="balance"
                       placeholder="请输入金额">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-6 col-sm-4 text-r">
                <span class="c-red">*</span>用户名：
            </label>
            <div class="formControls col-xs-6 col-sm-6">
                <select class="form-control" name="personId" id="personId">
                    <option value="">请选择用户名</option>
                    <option th:each="list:${teacherList}" th:value="${list.personId}" th:text="${list.personName }"></option>
                </select>
            </div>
        </div>
        <!--        <input type="hidden" id="id" name="id" value="${leaveInfo.id}"/>-->
        <div class="row cl" style="text-algin: center;">
            <div class="col-6 col-offset-5">
                <input class="btn btn-success radius" type="submit" value="保存" id="save-btn">
                <button type="button" class="btn btn-secondary radius" onclick="window.location.reload();">取消</button>
            </div>
        </div>
    </form>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="h-ui/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="h-ui/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="h-ui/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="h-ui/lib/jquery.validation/1.14.0/jquery.form.min.js"></script>
<script type="text/javascript" src="h-ui/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="h-ui/static/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="h-ui/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="h-ui/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
    $(function () {
        $("#addFrom").validate({
            rules: {
                cardNum: {
                    required: true,
                },
                personId: {
                    required: true
                },
                balance: {
                    required: true
                }
            },
            messages: {
                cardNum: {
                    required: "课表名称不能为空",
                },
                personId: {
                    required: "请选择班级"
                },
                balance: {
                    required: "请选择班级"
                }
            },
            onkeyup: false,
            focusCleanup: false,
            success: "valid",
            submitHandler: function () {
                fromSubmit();
            }
        });

    });

    // 提交保存
    $("#save-btn").click(function () {
        $("#addFrom").submit();
    })

    function fromSubmit() {
        $('#save-btn').attr("disabled", "disabled");
        $("#addFrom").ajaxSubmit({
            url: "schedule/Insertschedule",
            type: "post",
            dataType: "json",
            success: function (result) {
                if (result.sucess) {
                    layer.msg(result.msg, {
                        icon: 1,//提示的样式
                        time: 2000,
                        end: function () {
                            parent.location.reload()
                            layer_close();
                            // 刷新父页面列表并关闭编辑窗口
                            // layer_close();
                            // parent.table.ajax.reload();
                            // refreshParentAndClose(window.parent.rctable);
                        }
                    });
                } else {
                    $('#save-btn').removeAttr("disabled");
                    layer.msg(result.msg, {
                        icon: 2,
                        time: 2000
                    });
                }
            }
        });
    }
</script>
</body>
</html>